package java_io;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileCopy {

	public static void main(String[] args) {
		final String dir = System.getProperty("user.dir");
		
		Path path = Paths.get(dir + "\\bin\\javacore\\io\\contacts.csv");
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
		Date date = new Date();
		String today = dateFormat.format(date);
		System.out.println(today);
		Path newFile = Paths.get(dir + "\\bin\\javacore\\io\\contacts" + today + ".csv");
		try{
			System.out.println("Copying File...");
			Files.copy(path, newFile, REPLACE_EXISTING);
		}catch(IOException ex){
			System.err.format("IOException: %s%n", ex);
		}
		
		System.out.println("File is copied to " + newFile.toString());
	}

}
